package top.mybatisx.sql.core.sql;

import top.mybatisx.sql.core.sql.base.BaseSql;
import top.mybatisx.sql.core.toolkit.ChkUtil;

/**
 * 查询
 */
public interface Having<T extends OrderBy> extends BaseSql {

    StringBuilder havingSql = new StringBuilder();


    default T havingSql(String sql) {
        havingSql.append(sql);
        return (T) this;
    }


    default String buildHavingSql() {
        if (havingSql.length() > 0 || ChkUtil.isNull(havingList)) {
            // 如果手工设置了 sql, 直接返回
            return havingSql.toString();
        }

        havingSql.setLength(0);
        havingSql.append(" having ");

        String allCondSql = getAllCondSql(havingList);
        havingSql.append(allCondSql);

        return havingSql.toString();
    }
}
